alter procedure p_getnewbomcopyold
(
  @bomid integer,
  @create_by integer,
  @nbomid integer output
)
as
begin
  declare @code nvarchar(40),@name nvarchar(60)
  exec p_getnewkey 'td_productbomver', @nbomid output
  select @code=p.code+' '+CONVERT(varchar,GETDATE(),120),@name=p.name+' '+CONVERT(varchar,GETDATE(),120) 
    from td_product p,td_productbomver v where v.bomid=@bomid and p.p_id=v.productid
  
  insert into td_productbomver (bomid,code,name,create_time,create_by
      ,productid,quantity,qtypercent,state,manhour,pretime,cost,salereprice,remark,defbom
      ,custom1,custom2,custom3,custom4,custom5,custom6,custom7,custom8,custom9,custom10
      ,custom11,custom12,custom13,custom14,custom15) 
    select @nbomid,@code,@name,GETDATE(),@create_by
      ,productid,quantity,qtypercent,0,manhour,pretime,cost,salereprice,remark,0
      ,custom1,custom2,custom3,custom4,custom5,custom6,custom7,custom8,custom9,custom10
      ,custom11,custom12,custom13,custom14,custom15        
       from td_productbomver where bomid=@bomid  
       
  select * into #bomtmp from td_productbom where bomid=@bomid
  update #bomtmp set bomid=@nbomid
  insert into td_productbom select * from #bomtmp
  drop table #bomtmp
  
  select * into #bomsubtmp from td_productbomsub where bomid=@bomid
  update #bomsubtmp set bomid=@nbomid
  insert into td_productbomsub select * from #bomsubtmp
  drop table #bomsubtmp
  
  select * into #bomproctmp from td_productbomproc where bomid=@bomid
  update #bomproctmp set bomid=@nbomid
  insert into td_productbomproc select * from #bomproctmp
  drop table #bomproctmp
  
end